// 管理路由规则的模块
import { constantRoutes, asyncRoutes } from '@/router'
export default {
  state() {
    return {
      routes: constantRoutes
    }
  },
  mutations: {
    setRoutes(state, filterRoutes) {
      // state.routes.push(...filterRoutes)
      state.routes = [...constantRoutes, ...filterRoutes, { path: '*', redirect: '/404', hidden: true }]
    }
    /*  resetRoutes(state) {
      state.routes = [...constantRoutes, { path: '*', redirect: '/404', hidden: true }]
    } */
  },
  actions: {
    // 过滤操作封装到action中
    filterMethod({ commit }, menus) {
      const filterRoutes = asyncRoutes.filter(item => {
        return menus.includes(item.children[0].name)
      })
      commit('setRoutes', filterRoutes)
      return filterRoutes
    }
  },
  getters: {},
  namespaced: true
  // 一定记得挂载到index的modules节点上
}
